/*
 * charger-ss805x-priv.h
 *
 * charger driver.
 *
 * Copyright (C) 2024 Sinh Micro, Inc.
 * Subject to the GNU Public License, version 2.
 *
 * Author: lixiang<lixiang@sinhmicro.com>
 * 
 * Encoding format: GB2312
 * Version: v1.2.2
 * Date: 2024-11-05
 */
 
#ifndef _CHARGER_SS805X_PRIV_H_
#define _CHARGER_SS805X_PRIV_H_

#include "hal-config.h"
#include "hal-regs.h"

#include "types.h"

extern bool chg_abn_temp;

#define CHARGER_FULL_VOL                (CONFIG_BAT_FULL_VOLTAGE - 90)
#define CONFIG_CHARGER_RC_VOL           (CONFIG_BAT_FULL_VOLTAGE - 150)
#define CONFIG_CHARGER_ISET_VALUE       (CONFIG_CHARGER_ISET / 50 -1)

#define CONFIG_CHARGER_USING_TIMEOUT    (1)
#define CONFIG_CHARGER_TIMEOUT_VALUE    (CONFIG_CHARGER_TIMEOUT)
                              
#if (CONFIG_BAT_FULL_VOLTAGE == 4100)
    #define CONFIG_CHARGER_VSET         (0)
#elif (CONFIG_BAT_FULL_VOLTAGE == 4150)
    #define CONFIG_CHARGER_VSET         (1)
#elif (CONFIG_BAT_FULL_VOLTAGE == 4200)
    #define CONFIG_CHARGER_VSET         (2)
#elif (CONFIG_BAT_FULL_VOLTAGE == 4250)
    #define CONFIG_CHARGER_VSET         (3)
#elif (CONFIG_BAT_FULL_VOLTAGE == 4300)
    #define CONFIG_CHARGER_VSET         (4)    
#elif (CONFIG_BAT_FULL_VOLTAGE == 4350)
    #define CONFIG_CHARGER_VSET         (5)
#elif (CONFIG_BAT_FULL_VOLTAGE == 4400)
    #define CONFIG_CHARGER_VSET         (6)             
#elif (CONFIG_BAT_FULL_VOLTAGE == 4450)
    #define CONFIG_CHARGER_VSET         (7)
#endif
          
#define CHGCON0_INIT_VALUE  ((1 << 6) |\
                             (CONFIG_CHARGER_TLP_THRESH << 4) |\
                             (1))

#define CHGCON1_INIT_VALUE  (0x05)
                             
#define CHGCON2_INIT_VALUE  ((0 << 7) |\
                             (1 << 6) |\
                             (1))

#define CONFIG_CHARGER_SLOW_START       (0)                             
#if (CONFIG_CHARGER_SLOW_START == 0)
#define CHGCON3_INIT_VALUE  ((CONFIG_CHARGER_ISET_VALUE << 3) |\
                             (CONFIG_CHARGER_VSET))
#else
#define CHGCON3_INIT_VALUE  (CONFIG_CHARGER_VSET)
#endif
                             
#define CHGCON4_INIT_VALUE  ((1 << 6) |\
                             (CONFIG_CHARGER_USING_TLP << 5) |\
                             (CONFIG_CHARGER_TIMEOUT_VALUE << 2) |\
                             (CONFIG_CHARGER_USING_TIMEOUT << 1))

#endif